<template>
  <view class="cart-container">
    <!-- 商品列表标题 -->
    <view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <text class="cart-title-text">购物车</text><text class="cart-title-text1">({{total}})</text>
    </view>
    <view class="box_null">
      <myaddress ></myaddress>
    </view>
    <view  v-if="cart.length !== 0">
      <!-- 商品列表 -->
      <uni-swipe-action >
        <view class="box-data" v-for="(goods,i) in cart" :key="i" >
          <uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
          <my-goods :goods="goods" :show-radio="true"  :show-num="true" @radio-change="radioChangeHandler" @num-change="numberChangeHandler"></my-goods>
          </uni-swipe-action-item>
        </view>
        
      </uni-swipe-action>
      
    </view>
    <view class="empty-cart" v-else>
      <image src="/static/cart_empty@2x.png"  class="empty-img" ></image>
      <text class="tip-text">暂无商品，快去添加购物车~</text>
    </view>
    <mysettle></mysettle>
  </view>
</template>

<script>
  import {mapState,mapMutations} from 'vuex'
  import badgeMix from '@/mixins/tabbar-badge.js'
  export default {
    mixins:[badgeMix],
    computed:{
      ...mapState('m_cart',['cart'])
    },
    data() {
      return {
        options:[{
          text:'删除',
          style:{
            backgroundColor:'#c00000'
          }
        }]
      };
    },
    methods:{
      radioChangeHandler(e){
        this.updataGoodsState(e)
      },
      ...mapMutations('m_cart',['updataGoodsState','updataGoodsCount','removeGoodsById']),
      
      numberChangeHandler(e){
        this.updataGoodsCount(e)
      },
      swipeActionClickHandler(goods){
        this.removeGoodsById(goods)
      }
      
    }
    
  }
</script>

<style lang="scss">
  .cart-container{
    padding-bottom: 35px;
    padding-top: 130px;
    
.cart-title{
  height: 40px;
  display: flex;
  z-index: 100;
  font-size: 18px;
  width: 100%;
  position: fixed;
  top: 0px;
  box-sizing: border-box;
  padding-left: 5px;
  background: #f7acbc;
  border-bottom: 1px solid #efefe;
  .cart-title-text{
    margin-left: 5px;
    color: #000;
  }
  .cart-title-text1{
    margin-left: 3px;
    font-size: 15px;
  }
}
 .box_null{
    background-color: #fff;
    position: fixed;
    top: 30px;
    height: 90px;
    width: 100%;
    z-index: 100;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    
  }
  .empty-cart{
    display: flex;
    padding-top: 180rpx;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    .empty-img{
      width: 90px;
      height: 90px;
    }
    .tip-text{
      font-size: 12px;
      color: gray;
      margin-top: 15px;
    }
  }
  }
</style>
